Use GIO for this.
authorMatthias Clasen <matthiasc@src.gnome.org>
Thu, 19 Jun 2008 19:04:22 +0000 (19:04 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 19 Jun 2008 19:04:22 +0000 (19:04 +0000)
        * gtk/gtkrecentmanager.c (get_icon_for_mime_type): Use GIO
        for this.

svn path=/trunk/; revision=20472

ChangeLog
gtk/gtkrecentmanager.c

index d095548a998dccd5f6c2693df58ebdce2529eec6..01019bb0b126835e4568eaa425152cca31747724 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-06-19  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkrecentmanager.c (get_icon_for_mime_type): Use GIO
+       for this.
+
 2008-06-19  Johan Dahlin  <jdahlin@async.com.br>
 
        * gtk/gtkprintbackend.c: Fix a typo in a comment
index 39a3242e9daecf57277ef9cb436c36797b6940e6..1b24425384704af0d38da64ad01efa751ab30b91 100644 (file)
@@ -1881,52 +1881,24 @@ get_icon_for_mime_type (const char *mime_type,
                        gint        pixel_size)
 {
   GtkIconTheme *icon_theme;
-  const char *separator;
-  GString *icon_name;
+  char *content_type;
+  GIcon *icon;
+  GtkIconInfo *info;
   GdkPixbuf *pixbuf;
 
-  separator = strchr (mime_type, '/');
-  if (!separator)
-    return NULL;
-
   icon_theme = gtk_icon_theme_get_default ();
 
-  /* try with the three icon name variants for MIME types */
-
-  /* canonicalize MIME type: foo/x-bar -> foo-x-bar */
-  icon_name = g_string_new (NULL);
-  g_string_append_len (icon_name, mime_type, separator - mime_type);
-  g_string_append_c (icon_name, '-');
-  g_string_append (icon_name, separator + 1);
-  pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
-                                     pixel_size,
-                                     0,
-                                     NULL);
-  g_string_free (icon_name, TRUE);
-  if (pixbuf)
-    return pixbuf;
-
-  /* canonicalize MIME type, and prepend "gnome-mime-" */
-  icon_name = g_string_new ("gnome-mime-");
-  g_string_append_len (icon_name, mime_type, separator - mime_type);
-  g_string_append_c (icon_name, '-');
-  g_string_append (icon_name, separator + 1);
-  pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
-                                     pixel_size,
-                                     0,
-                                     NULL);
-  g_string_free (icon_name, TRUE);
-  if (pixbuf)
-    return pixbuf;
-
-  /* try the MIME family icon */
-  icon_name = g_string_new ("gnome-mime-");
-  g_string_append_len (icon_name, mime_type, separator - mime_type);
-  pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
-                                     pixel_size,
-                                     0,
-                                     NULL);
-  g_string_free (icon_name, TRUE);
+  content_type = g_content_type_from_mime_type (mime_type);
+  icon = g_content_type_get_icon (content_type);
+  info = gtk_icon_theme_lookup_by_gicon (icon_theme, 
+                                         icon, 
+                                         pixel_size, 
+                                         GTK_ICON_LOOKUP_USE_BUILTIN);
+  pixbuf = gtk_icon_info_load_icon (info, NULL);
+
+  g_free (content_type);
+  g_object_unref (icon);
+  gtk_icon_info_free (info);
 
   return pixbuf;
 }